package mobi.yuanshen.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class TimeAspect {

    @Pointcut("execution(* mobi.yuanshen.service.*.*(..))") // 切点
    private void pt () {}

    @Around("pt()")// 切入点表达式
    public Object recordTime (ProceedingJoinPoint joinPoint) throws Throwable {
        // 记录开始时间
        long begin = System.currentTimeMillis();
        // 原始方法执行
        Object result = joinPoint.proceed();
        // 记录结束时间
        System.out.println(joinPoint.getSignature()
                +  "方法耗时:"
                + (System.currentTimeMillis() - begin) + "毫秒");
        return result;
    }

}
